package com.raccoonagents.tools.cascet2d.model.components;

import com.raccoonagents.tools.cascet2d.interfaces.rendering.IRenderableObject;
import com.raccoonagents.tools.cascet2d.model.Vector2f;
import com.raccoonagents.tools.cascet2d.util.FWLogger;
import com.raccoonagents.tools.cascet2d.util.GraphicUtil;

public class DefaultProgressBar extends AbstractStageComponent implements IRenderableObject{

	protected int maxProgress = -1;

	protected float [] progressColor = new float []{1.0f,0.0f,0.0f};
	protected float [] bgColor = new float []{0.1f,0.1f,0.1f};

	protected int barHeight;
	protected int maxBarWidth;
	protected float opacity = 1.0f;
	private int currentProgress;

	public float[] getBgColor() {
		return bgColor;
	}

	public void setBgColor(final float[] bgColor) {
		this.bgColor = bgColor;
	}
	
	public DefaultProgressBar(final int maxBarWidth, final int barHeight){
		this.maxBarWidth = maxBarWidth;
		this.barHeight = barHeight;
		this.size = new Vector2f(maxBarWidth, barHeight);
	}
	
	/**
	 * 
	 * @return
	 */
	public int getMaxProgress() {
		return maxProgress;
	}

	public void setMaxProgress(final int maxProgress) {
		this.maxProgress = maxProgress;
	}

	public int getCurrentProgress() {
		return currentProgress;
	}

	public void setCurrentProgress(final int currentProgress) {
		this.currentProgress = currentProgress;
	}

	public void increase(){
		this.currentProgress +=1;
	}
	
	

	@Override
	public void render() {
		if(!visible){
			return;
		}
		if(maxProgress == -1){
			FWLogger.warning("progressbar max progress is unitialized!");
			return;
		}
		GraphicUtil.renderRectangle(this);
		// GraphicUtil.renderRectangle(this.getLocation(), size, opacity, color)
		final float increment = (float)this.maxBarWidth / (float)this.maxProgress;
		final float progressPoint = increment * currentProgress;
		
		if(increment * currentProgress <= maxBarWidth){
			GraphicUtil.renderRectangle(this.getLocation(), new Vector2f(progressPoint, barHeight), opacity, this.progressColor, this.getPivot());					
		}else{
			GraphicUtil.renderRectangle(this.getLocation(), new Vector2f(maxBarWidth, barHeight), opacity, this.progressColor, this.getPivot());					
			
		}
	}

	@Override
	public float[] getColor() {
		return bgColor;
	}

	@Override
	public float getOpacity() {
		return opacity;
	}


	@Override
	public float getRotation() {
		return 0;
	}
	public float[] getProgressColor() {
		return progressColor;
	}

	public void setProgressColor(final float[] progressColor) {
		this.progressColor = progressColor;
	}

	@Override
	public Vector2f getPivot() {
		return null;
	}


}
